package com.object.module.lq.sys.controller;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import cn.dev33.satoken.stp.StpUtil;
import com.object.module.lq.sys.entity.TNotice;
import com.object.utils.Q;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import com.object.module.lq.sys.service.TNoticeService;
import javax.annotation.Resource;


/**
 * 通知
 *
 * @author 小庆
 **/
@RestController
@RequestMapping("/TNotice")
@Api(tags = "通知接口")
public class TNoticeController
{
    @Resource
    private TNoticeService service;


    @ApiOperation("查询自己的通知-传人通知类型")
    @GetMapping("/list/{type}")
    public Q list(@PathVariable("type")Integer type)
    {
        return service.listPage(type);
    }

    @ApiOperation("查询自己的通知-传人通知类型")
    @GetMapping("/list")
    public Q<List<TNotice>> listPage(Map<String, Object> pram)
    {
        return service.listPage(pram);
    }

    @ApiOperation("创建通知")
    @PostMapping("/save")
    public Object save(@RequestBody TNotice bean)
    {
        bean.setTnUr(Integer.parseInt(StpUtil.getLoginId().toString()));
        bean.setTnTime(new Date());
        bean.setTnStats(1);
        return Q.ok().q("data", service.save(bean));
    }

    @ApiOperation("修改根据id")
    @PostMapping("/update")
    public Object update(@RequestBody TNotice bean)
    {
        return Q.ok().q("data", service.updateById(bean));
    }

    @ApiOperation("批量操作")
    @PostMapping("/batchWord")
    public Object update(@RequestBody List<TNotice> beans)
    {
        return Q.ok().q("data", service.updateBatchById(beans));
    }

    @ApiOperation("删除根据id")
    @DeleteMapping("/delete")
    public Object delete(@RequestBody String[] ids)
    {
        return Q.ok().q("data", service.removeByIds(Arrays.asList(ids)));
    }
}